@layout AuthLayout

@page "/signup"

@inject ScriptHelpers ScriptHelpers

<form
    class="auth-form-root"
    @onsubmit="@HandleSignUp">
    <Typography
        Class="auth-form-title"
        Variant="TypographyVariant.H2">
        Create new account
    </Typography>
    <Typography
        Color="@Color.TextSecondary"
        GutterBottom>
        Use your email to create new account
    </Typography>
    <TextField
        Class="auth-form-text-field"
        FullWidth
        Label="First Name"
        Name="firstName"
        OnChange="@HandleFirstNameChange"
        Type="text"
        Value="@FirstName"
        Variant="@TextFieldVariant.Outlined" />
    <TextField
        Class="auth-form-text-field"
        FullWidth
        Label="Last Name"
        Name="lastName"
        OnChange="@HandleLastNameChange"
        Type="text"
        Value="@LastName"
        Variant="@TextFieldVariant.Outlined" />
    <TextField
        Class="auth-form-text-field"
        FullWidth
        Label="Email address"
        Name="email"
        OnChange="@HandleEmailChange"
        Type="text"
        Value="@Email"
        Variant="@TextFieldVariant.Outlined" />
    <TextField
        Class="auth-form-text-field"
        FullWidth
        Label="Password"
        Name="password"
        OnChange="@HandlePasswordChange"
        Type="password"
        Value="@Password"
        Variant="@TextFieldVariant.Outlined" />
    <div class="auth-form-policy-field">
        <Checkbox
            Checked="@Policy"
            Class="auth-form-policy-checkbox"
            Color="@Color.Primary"
            Name="policy"
            OnChange="@HandlePolicyChange" />
        <Typography
            Class="auth-form-policy-text"
            Color="@Color.TextSecondary"
            Variant="@TypographyVariant.Body1">
            I have read the Terms and Conditions
        </Typography>
    </div>
    <Button
        Class="auth-form-submit-button"
        Color="@Color.Primary"
        FullWidth
        Size="@Size.Large"
        Type="@ButtonType.Submit"
        Variant="@ButtonVariant.Contained">
        Sign up now
    </Button>
    <Typography
        Color="@Color.TextSecondary"
        Variant="@TypographyVariant.Body1">
        Have an account?
        <NavLink href="signin" Match="NavLinkMatch.Prefix">
            Sign in
        </NavLink>
    </Typography>
</form>

@code
{
    private string FirstName { set; get; }

    private string LastName { set; get; }

    private string Email { set; get; }

    private string Password { set; get; }

    private bool Policy { set; get; }

    private void HandlePolicyChange(ChangeEventArgs arg)
    {
        Policy = !Policy;

        StateHasChanged();
    }

    private void HandleFirstNameChange(ChangeEventArgs arg)
    {
        FirstName = arg.Value.ToString();

        StateHasChanged();
    }

    private void HandleLastNameChange(ChangeEventArgs arg)
    {
        LastName = arg.Value.ToString();

        StateHasChanged();
    }

    private void HandleEmailChange(ChangeEventArgs arg)
    {
        Email = arg.Value.ToString();

        StateHasChanged();
    }

    private void HandlePasswordChange(ChangeEventArgs arg)
    {
        Password = arg.Value.ToString();

        StateHasChanged();
    }

    private void HandleSignUp()
    {
        System.Console.WriteLine("HandleSignUp");

         _ = ScriptHelpers.GoBackAsync();

        System.Console.WriteLine("HandleSignUpDone");
    }
}
